package moon.excel.constants;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;

import org.apache.commons.beanutils.Converter;

import moon.excel.util.ExcelUtil;
import moon.util.DateUtils;

public class ExcelConstants {
	public static Map<Character, Integer> columnMap = new HashMap<Character, Integer>();
	/** 读取模型 基于事件的模型 */
	public static final Integer READE_MODEL_EVENT = 0;
	/** 普通模型 */
	public static final Integer READE_MODEL_DOM = 1;

	public static MimeType MIMETYPE_XLS = null;// xls
	public static MimeType MIMETYPE_XLSX = null;// xlsx

	static {
		columnMap.put('A', 1);
		columnMap.put('B', 2);
		columnMap.put('C', 3);
		columnMap.put('D', 4);
		columnMap.put('E', 5);
		columnMap.put('F', 6);
		columnMap.put('G', 7);
		columnMap.put('H', 8);
		columnMap.put('I', 9);
		columnMap.put('J', 10);
		columnMap.put('K', 11);
		columnMap.put('L', 12);
		columnMap.put('M', 13);
		columnMap.put('N', 14);
		columnMap.put('O', 15);
		columnMap.put('P', 16);
		columnMap.put('Q', 17);
		columnMap.put('R', 18);
		columnMap.put('S', 19);
		columnMap.put('T', 20);
		columnMap.put('U', 21);
		columnMap.put('V', 22);
		columnMap.put('W', 23);
		columnMap.put('X', 24);
		columnMap.put('Y', 25);
		columnMap.put('Z', 26);
		ExcelUtil.convertUtilsBean.register(new Converter() {
			@SuppressWarnings({ "rawtypes", "unchecked" })
			@Override
			public Object convert(Class type, Object value) {
				return DateUtils.parseDate(value.toString());
			}

		}, Date.class);
	}

	static {
		try {
			MIMETYPE_XLS = new MimeType("application/vnd.ms-excel");
			MIMETYPE_XLSX = new MimeType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
		} catch (MimeTypeParseException e) {
			e.printStackTrace();
		}
	}

	public ExcelConstants() {
	}

}
